package example.com.terry.utils;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

public class CookieUtils {
    // 判断是否是登陆状态
    public static boolean isSign(HttpServletRequest request) {
        boolean flag = false;
        Cookie[] cookies = request.getCookies();
        if (cookies != null) {
            for (Cookie cookie : cookies) {
                flag = cookie.getName().equals("username");
                if (flag) {
                    break;
                }
            }
        }

        return flag;

    }

    public static String getUser(HttpServletRequest request) {
        boolean flag = false;
        String userName = "";
        Cookie[] cookies = request.getCookies();
        for (Cookie cookie : cookies) {
            flag = cookie.getName().equals("username");
            if (flag) {
                userName = cookie.getValue();

                break;
            }
        }

        return userName;

    }
}
